﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BiliBiliCSharpStudy.old {
    /**
     * 扩展方法（this参数）
     */
    class ParametersExtensionDemo {
        public static void demo() {
            //test1();
            test2();
        }

        public static void test2() {
            List<int> myList = new List<int>() { 9, 11, 12, 13, 14, 15, 16 };
            bool result = AllGreaterThanTen(myList);
            Console.WriteLine(result);
            // Linq
            result = myList.All(i => i > 10);
            Console.WriteLine(result);
        }

        public static void test1() {
            double x = 3.14159;
            double y = Math.Round(x, 4);
            Console.WriteLine("x: {0}, y: {1}", x, y);
            double z = x.Round(4);
            Console.WriteLine("x: {0}, z: {1}", x, z);
        }

        static bool AllGreaterThanTen(List<int> intList) {
            foreach (var item in intList) {
                if (item <= 10) {
                    return false;
                }
            }
            return true;
        }
    }

    static class DoubleExtension {
        public static double Round(this double input, int digits) {
            double result = Math.Round(input, digits);
            return result;
        }
    }

}
